import React from 'react'
import { NavBar, Icon} from 'antd-mobile'
import { withRouter } from 'react-router-dom'
import styles from './index.module.css'
import PropTypes from 'prop-types' // props校验,增加代码的健壮性
 class NavHeader extends React.Component {
   // 默认事件
  defaultClick = () => this.props.history.go(-1)
  render () {
    return (
         <NavBar
        className={styles.navBar}
        mode="light"
        icon={<Icon type="left" />}
        // 若有传入的事件就执行
        onLeftClick={ this.props.onLeftClick || this.defaultClick}
        // 右侧显示的图标
        rightContent={this.props.rightContent}
      >{this.props.children}
      </NavBar>
    )
  }
}
NavHeader.propTypes = {
  children: PropTypes.string.isRequired,
  onLeftClick: PropTypes.func
}
export default withRouter(NavHeader)